Skip to content

fix(opencode-claimant): migration-0026 restores guarded lane-session recovery (#5400) - #8384

Merged
dezren39 merged 2 commits into
mainfrom
queue/10895-5400-migration-0025
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/10895-5400-migration-0025

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #5400. Queue task 10895.

What

Adds pm-stack/opencode-claimant/migration-0026.sql: migration-0024's bind_repo_task_lane_session definition with the migration-0022 guarded recovery modes restored ahead of the normal-bind guard. The 0023/0024 record copies had dropped the recovery branches, so the claimant recovery operation documented in prompt.md — invoked only after lease expiry — was rejected by the function's own claimed + live-lease guard.

Note on numbering: the packet for task 10895 named this migration 0025, but 0025 was taken on main by the #5444 claim-payload fix after the packet was written, so the fix lands as 0026.

Decisions

  • Task-row-first lock order (migration-0024, Codex finding 4465191796) is preserved in both branches; the recovery branch then locks the ledger row FOR UPDATE, as 0022 did.
  • The normal branch is migration-0024 unchanged: a normal bind still requires a claimed task with a live lease.
  • The open detail from triage task 10034 is decided: recovery requires status claimed AND an expired lease. prompt.md invokes recovery only after lease expiry, and a live lease means the bound session's launch window is still owned — recovery against a live lease is refused, so a stale claimant cannot clear a binding whose session may still legitimately launch.
  • Recovery still requires worker opencode-claimant, the prior session id matching BOTH progress.session_id and the lane ledger (any mismatch raises and leaves both stores unchanged), and attempts remaining; it clears both bindings atomically, records stage launch_failed with the prior id and reason, and consumes one attempt.

Tests

test/test_migration_0026.sh spins up a scratch Postgres (socket-only, removed on exit), applies a minimal agent schema, migration-0026, and 8 asserted scenarios in test/migration-0026.test.sql: both recovery reasons clear both stores and consume an attempt; mismatch refusal leaves both stores unchanged; live-lease recovery refused; non-claimant recovery refused; attempts-exhausted refused; normal live-lease bind binds both stores; normal expired-lease bind refused. Result: all 8 scenarios passed on the laptop.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…recovery (#5400)

migration-0023/0024 record copies dropped the migration-0022 recovery modes from bind_repo_task_lane_session, so the claimant recovery operation in prompt.md (invoked only after lease expiry) was rejected by the live-lease guard. migration-0026 merges the two reserved recovery modes back into the migration-0024 definition: task-row-first locking preserved, normal bind unchanged, recovery compare-and-clears the prior session id against both stores, consumes one attempt, and requires an expired lease. Focused tests: test/test_migration_0026.sh (scratch Postgres, 8 scenarios).
@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 01:14
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74469aaf-192c-4c6f-a038-7327d0c1147d
Commits

Reviewing files that changed from the base of the PR and between f731530 and 892b99a.

Files selected for processing: 4

  • pm-stack/opencode-claimant/migration-0026.sql
  • pm-stack/opencode-claimant/test/migration-0026.schema.sql
  • pm-stack/opencode-claimant/test/migration-0026.test.sql
  • pm-stack/opencode-claimant/test/test_migration_0026.sh
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T01:27:26.055059Z 892b99a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e02e786759

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +106 to +108
update agent.tasks
set attempts = coalesce(attempts, 0) + 1,
progress = coalesce(progress, '{}'::jsonb)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore launch eligibility when clearing a recovered binding

For tasks recovered through this PostgreSQL function, recovery requires an expired lease but this update leaves that lease unchanged. The recovered task therefore becomes an unbound launch_failed candidate that cannot pass the normal-bind live-lease guard at lines 127–129. In claimant.py, launch_step does not renew or reclaim these claimed candidates before binding; it creates a replacement session, encounters the bind failure, and deletes the replacement without prompting it. Restore a valid claim/lease transition as part of recovery or before relaunch, and cover recovery followed by a normal bind in the tests; the current isolated recovery assertions miss this failure.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposition: not a defect in this migration — launch eligibility is restored by the broker's expiry/collection transition, not by the bind call, and the sequence is now covered by a test (scenario S9, head 892b99a).

Evidence from the live system this record mirrors:

  • The recovered row (claimed, expired lease, progress lane opencode + stage launch_failed) is exactly the broker's handoff shape. expire_leases in pkgs/fleet/crates/fleet-queue/src/turso_queue.rs returns such rows to the handoff sink on expiry, and the claimant collects sink candidates with claim --handoff — a fresh claim with a new live lease — before launch_step launches and binds. launch_step binds claimed candidates directly only when they were just collected that way; a resting launch_failed row reaches it via the sink, never with the expired lease still attached.
  • poll.py documents the same contract: stage launch_failed is a launch-safe yield precisely because recovery atomically cleared both bindings; relaunch happens after collection.
  • The live verb_bind renews nothing: it has the same live-lease guard and no lease mutation, so adding lease renewal inside the PostgreSQL recovery branch would make this record diverge from the live contract it copies.

What changed in response to the finding: the migration-0026 header now documents this eligibility path explicitly, and test/migration-0026.test.sql gains scenario S9 — recovery, then the expiry/collection transition under a fresh claim lease, then a normal bind of the replacement session succeeds against both stores. All 9 scenarios pass (test/test_migration_0026.sh, scratch Postgres).

@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · shepherd review — merging (task 10895, issue #5400)

  • This lane claimed task 10895 and found this PR already authored by the task's earlier attempt (head 892b99a). I reviewed it as the merging lane rather than duplicating the work.
  • Codex gate: one P2 finding (4532700846 — recovery leaves the lease expired, so a recovered row cannot pass the normal-bind live-lease guard). It was dispositioned on-thread by the author with the S9 test; I re-verified the disposition independently: expire_leases / sink collection in pkgs/fleet/crates/fleet-queue/src/turso_queue.rs treats launch_failed rows as handoff-sink candidates (line ~2213, with a sink-yield test at ~6998), so a recovered row is freshly claimed with a live lease before any normal bind — the lease is restored by the claim transition, not the bind call.
  • Verification (laptop, this shift): test/test_migration_0026.sh against a scratch Postgres — all 9 scenarios pass, including S9 (recovery → fresh claim → normal bind binds both stores). PR is MERGEABLE against current main; migration number 0026 is still free (0025 on main is the repo-queue: claim can hand out a payload-null task, and list views cannot recover a live claim by lane #5444 claim-payload migration).
  • Merging on the standing authority (targeted tests verified locally; PR checks are QUEUED in the runner jam). A misdirected comment for PR fix(aggregator): gate aa configs/testRuns/coverage/catalog/cai at render depth (#4169) #4565 was posted here in error moments ago and deleted immediately; this note replaces it.

@dezren39
dezren39 merged commit 23e3b1d into main Nov 11, 2026
1 of 8 checks passed
@dezren39
dezren39 deleted the queue/10895-5400-migration-0025 branch November 11, 2026 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opencode-claimant: restore bind_repo_task_lane_session guarded recovery mode dropped by migration-0023

1 participant